<?php

namespace plugin\admin\app\model;

use Illuminate\Database\Eloquent\Casts\Attribute;
use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property integer $orderNo 
 * @property string $totalAmount 总金额
 * @property string $customerNumber 会员号
 * @property string $payMethod 支付方式
 * @property string $orderDateTime 订单产生的时间
 * @property string $orderSource 订单来源
 * @property integer $created_at 
 * @property integer $updated_at
 */
class Order extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_order';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $guarded = [];

    protected $dateFormat = 'U';


    protected function getPayMethodAttribute($value)
    {
        if (!empty($value)){
            switch ($value){
                case 'Cash':
                    return '现金';
                case 'CustomerBalance':
                    return '余额';
                default:
                    return '其他';
            }
        }
        return '未知';
    }

    protected function getOrderSourceAttribute($value)
    {
        if (!empty($value)){
            switch ($value){
                case 'MEITUAN_WAIMAI':
                    return '美团外卖';
                case 'ELEME_WAIMAI':
                    return '饿了么';
                case 'ELEBE_WAIMAI':
                    return '饿百';
                case 'ZIYING_MINIAPP':
                    return '银豹小程序';
                case 'ZIYING_MIAOSHA':
                    return '秒杀单';
                case 'ZIYING_KANJIA':
                    return '砍价';
                default:
                    return '其他';
            }
        }
        return '未知';
    }

    public function user()
    {
        return $this->hasOne(YbUser::class, 'customer_uid', 'customer_id');

    }

    
    
}
